﻿using Oliving.Edge.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Oliving.Edge.Extensions.XcxExtentsions
{
    public class wxCode
    {
        public string openid { get; set; }
        public string session_key { get; set; }
        public string unionid { get; set; }
        public int errcode { get; set; }
        public string errmsg { get; set; }

    }
    public class WxLogin
    {
        public async Task<wxCode> XloginByCode(string code)
        {
            //APPID
            string appid = Appsettings.app(new string[] { "wxSetting", "xappid" });
            //secret
            string secret = Appsettings.app(new string[] { "wxSetting", "xscert" });
            //url
            string url = Appsettings.app(new string[] { "wxSetting", "xcodeurl" });
            url = url + "appid=" + appid + "&secret=" + secret + "&js_code=" + code + "&grant_type=authorization_code";
            //获取用户授权信息
            wxCode result = await Common.Helper.CommHelper.GetResultAsync<wxCode>(url);
            return result;
        }
    }
}
